package com.zxp.springboot;

import cn.hutool.extra.spring.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.Map;

/**
 * @author shollin
 */
@SpringBootApplication
@Slf4j
@Import(SpringUtil.class)
@EnableAspectJAutoProxy(exposeProxy = true) // 开始aop注解，暴露动态代理
public class Hello01Application {

    public static void main(String[] args) {
        // 返回ioc容器
        ConfigurableApplicationContext run = SpringApplication.run(Hello01Application.class, args);

        String[] beanDefinitionNames = run.getBeanDefinitionNames();
        for(String beanDefinitionName : beanDefinitionNames) {
            //log.debug("容器里面的bean:" + beanDefinitionName);
        }
        System.out.println("===============================");

        ConfigurableEnvironment environment = run.getEnvironment();
        ConfigurableListableBeanFactory beanFactory = run.getBeanFactory();

        Map<String, Object> systemProperties = environment.getSystemProperties();
        Map<String, Object> systemEnvironment = environment.getSystemEnvironment();
        String[] defaultProfiles = environment.getDefaultProfiles();


        systemProperties.forEach( (k,v)->{
            //log.debug("系统属性:"+k + " value: "+v);
            //System.out.println("===============================");
        });
        systemEnvironment.forEach( (k,v)->{
            //log.debug("系统环境变量:"+k + " value: "+v);
            //System.out.println("===============================");
        });

        log.info("========= 获取组件 =======");
        // 获取组件
        Map<String, SpringUtil> beansOfType = run.getBeansOfType(SpringUtil.class);
        //System.out.println(beansOfType);


        log.debug("默认profiles: "+defaultProfiles.toString());
        log.info("项目启动完成...");
    }

}
